<template>
  <div class="page-article" id="page-article" v-if="model">
    <div class="d-flex py-3 px-2 border-bottom">
      <i class="iconfont icon-back text-blue"></i>
      <div class="flex-1 text-blue pl-3 pr-2 text-ellipsis">
        {{model.title}}
      </div>
      <div class="text-gary fs-xs">{{model.updatedAt | date}}</div>
    </div>
    <div class="px-3 a-body fs-lg" v-html="model.body"></div>
    <div class="px-3 border-top py-2 mt-3">
      <div class="d-flex ai-center">
        <i class="icon-baozhi iconfont"></i>
        <span class="text-blue fs-lg ml-1">相关资讯</span>
      </div>
      <router-link class="py-2" tag="div" :to="`/articles/${item._id}`" v-for="item in model.related" :key="item._id">{{item.title}}</router-link>
    </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
  export default {
    filters:{
      date(val){
        return dayjs(val).format('MM/DD')
      }
    },
    props:{
      id:{required:true}
    },
    data() {
      return {
        model:[]
      }
    },
    watch: {
      id:'feach'
    },
    created() {
      this.feach()
    },
    methods: {
      async feach(){
        const res = await this.$http.get(`articles/${this.id}`)
        this.model=res.data
      }
    },
  }
</script>

<style lang="scss">
.page-article{
  overflow: hidden;
  .a-bady{
    width: 100%;
    img{
      max-width: 100%;
      height: auto;
    }
    iframe{
      height: auto;
      max-width: 100%;
    }
  }
}
#page-article{
  img{
      max-width: 100%;
      height: auto;
    }
  iframe{
    height: auto;
    max-width: 100%;
  }
}
</style>